Add some more basic tests
authorMatthias Clasen <mclasen@redhat.com>
Sat, 25 Jun 2011 00:57:22 +0000 (20:57 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 5 Jul 2011 20:08:08 +0000 (16:08 -0400)
tests/a11y/text.c

index 083438b8fc7d915bea4bc67bc0c9dff331cfd09d..b66da911f1b81b83df9bf991bc714ac43e9f8949 100644 (file)
  */
 
 #include <gtk/gtk.h>
+#include <string.h>
+
+static void
+set_text (GtkWidget   *widget,
+          const gchar *text)
+{
+  if (GTK_IS_LABEL (widget))
+    gtk_label_set_text (GTK_LABEL (widget), text);
+  else if (GTK_IS_ENTRY (widget))
+    gtk_entry_set_text (GTK_ENTRY (widget), text);
+  else if (GTK_IS_TEXT_VIEW (widget))
+    gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)), text, -1);
+  else
+    g_assert_not_reached ();
+}
+
+static void
+test_basic (GtkWidget *widget)
+{
+  AtkText *atk_text;
+  const gchar *text = "Text goes here";
+  gchar *ret;
+  gint count;
+  gunichar c;
+
+  atk_text = ATK_TEXT (gtk_widget_get_accessible (widget));
+
+  set_text (widget, text);
+  ret = atk_text_get_text (atk_text, 5, 9);
+  g_assert_cmpstr (ret, ==, "goes");
+  g_free (ret);
+
+  ret = atk_text_get_text (atk_text, 0, 14);
+  g_assert_cmpstr (ret, ==, text);
+  g_free (ret);
+
+  ret = atk_text_get_text (atk_text, 0, -1);
+  g_assert_cmpstr (ret, ==, text);
+  g_free (ret);
+
+  count = atk_text_get_character_count (atk_text);
+  g_assert_cmpint (count, ==, g_utf8_strlen (text, -1));
+
+  c = atk_text_get_character_at_offset (atk_text, 0);
+  g_assert_cmpint (c, ==, 'T');
+
+  c = atk_text_get_character_at_offset (atk_text, 13);
+  g_assert_cmpint (c, ==, 'e');
+}
 
 typedef struct {
   gint count;
@@ -44,20 +93,6 @@ text_inserted (AtkText *atk_text, gint position, gint length, SignalData *data)
   data->length = length;
 }
 
-static void
-set_text (GtkWidget   *widget,
-          const gchar *text)
-{
-  if (GTK_IS_LABEL (widget))
-    gtk_label_set_text (GTK_LABEL (widget), text);
-  else if (GTK_IS_ENTRY (widget))
-    gtk_entry_set_text (GTK_ENTRY (widget), text);
-  else if (GTK_IS_TEXT_VIEW (widget))
-    gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)), text, -1);
-  else
-    g_assert_not_reached ();
-}
-
 static void
 test_text_changed (GtkWidget *widget)
 {
@@ -546,6 +581,7 @@ static void
 add_text_tests (GtkWidget *widget)
 {
   g_object_ref_sink (widget);
+  add_text_test ("/text/basic", (GTestFixtureFunc) test_basic, widget);
   add_text_test ("/text/words", (GTestFixtureFunc) test_words, widget);
   add_text_test ("/text/changed", (GTestFixtureFunc) test_text_changed, widget);
   g_object_unref (widget);